package com.first.community.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PaginationDTO<T> {

    private List<T> data;

    private boolean showPrevious;

    private  boolean showNext;

    private  boolean showFirstPage;

    private  boolean showEndPage;

    private Integer page;

    private  List<Integer> pages = new ArrayList<>();

    private Integer totalPage;



    public void setPagination(Integer totalCount, Integer page, Integer size) {

        this.page=page;
        //添加page
        pages.add(page);
        for(int i=1;i<=3;i++){
            if(page-i>0){
                pages.add(0,page-i);
            }
            if(page+i<=totalPage){
                pages.add(page+i);
            }
        }


        //判断showPrevious
        if(page==1){
            showPrevious=false;
        }else {
            showPrevious=true;
        }

        //判断showNext
        if(page==totalPage){
            showNext=false;
        }else {
            showNext=true;
        }


        //判断showFirstPage
        if(pages.contains(1)){
            showFirstPage=false;
        }else {
            showFirstPage=true;
        }

        //判断showEndPage
        if(pages.contains(totalPage)){
            showEndPage=false;
        }else{
            showEndPage=true;
        }


    }
}
